﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Brokers;
using ExpertMIS.Entities;

namespace ExpertMIS.Forums
{
    public partial class PostAction : ExpertMIS.Codes.PostPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if ("answer".Equals(Request["type"]))
                {
                    PostNewAnswer();
                    Response.Redirect("QuestionForm.aspx?oid=" + Request["txQuestion"]);
                }
            }
            catch
            {
                // write log

            }
        }

        private void PostNewAnswer()
        {
            AnswerBroker answerBroker = new AnswerBroker();

            AnswerEntity answer = answerBroker.NewEntity() as AnswerEntity;
            answer.Context = Request["txAnswer"];
            answer.QuestionOID = Request["txQuestion"];
            answer.UserOID = Environment.GetCurrentUser().OID;
            answer.ClientIP = ExpertMIS.Codes.Utility.GetClientIP();
            answer.Status = AnswerStatus.Normal;

            answerBroker.SaveEntity(answer, null);
        }

        protected override object LoadPageStateFromPersistenceMedium()
        {
            return null;
        }
    }
}
